import 'package:flutter/material.dart';

import 'package:flutter/material.dart';
import 'package:aweb5/base/BaseWidget.dart';
import 'package:aweb5/pages/HomeTab.dart';
import 'package:aweb5/util/WindowUtil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:aweb5/pages/CateTab.dart';
import 'package:aweb5/pages/Rank.dart';
//import 'package:aweb/pages/ShoppingCart.dart';
import 'package:aweb5/pages/ShoppingCart1.dart';
import 'package:badges/badges.dart';
import 'package:aweb5/pages/Member.dart';
//import 'package:amap_base_location/amap_base_location.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'HomeTabWeb.dart';
import 'package:flutter/services.dart';
import 'dart:io';
//import 'package:flutter_statusbar/flutter_statusbar.dart';
//import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
import 'dart:async';
import 'dart:convert';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:aweb5/bean/tencent_geo_entity.dart';
import 'package:aweb5/util/HttpClient.dart';
import 'package:aweb5/config/Config.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:aweb5/util/FileUtil.dart';
import 'package:aweb5/util/fluwxUtil.dart';
import 'package:aweb5/bean/link_entity.dart';
import 'package:aweb5/util/JsonUtil.dart';
import 'package:dio/dio.dart';
import 'package:aweb5/bean/wxpay_entity.dart';
import 'dart:async';
import 'package:aweb5/pages/WrongPage.dart';
import 'LoadingDialog.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
import 'package:aweb5/bean/payresult_entity.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/services.dart';
import 'package:aweb5/util/DialogUtil.dart';
//import 'package:jpush_flutter/jpush_flutter.dart';
//import 'package:jpush_flutter/jpush_flutter.dart' ;

class HomePage extends BaseWidget {
  @override
  State<HomePage> createState() => HomePageState();
}

class HomePageState extends BaseWidgetState<HomePage> {
  int currentTab = 0;
  int shoppongNum = 0;
  DateTime lastPopTime;
//  JPush jpush = new JPush();
  double width;
  WebViewController controller;
  int index = 0;
  String kNavigationExamplePage = '''
<!DOCTYPE html><html>
<head><title>Navigation Delegate Example</title></head>
<body>
<p style="visibility:hidden;">
The navigation delegate is set to block navigation to the youtube website.
</p>
<ul>
<ul><a href="https://www.youtube.com/">https://www.youtube.com/</a></ul>
<ul ><a id="p1" href="https://www.google.com/">https://www.google.com/</a></ul>
</ul>
<script>
function callJS(message){
//  alert("1");
//document.getElementById("p1").style.visibility = message;
document.getElementById("p1").innerText = message;
}
</script> 


</body>
</html>
''';
  double lat = 0;
  double lng = 0;
  Dio dio;
  String data = "1.在浏览使用时，我们会收集、使用设备标识信息用于推荐。\n2.我们可能会申请位置权限，用于帮助你在发布的信息中展示位置或丰富信息推荐维度。城市位置无需使用位置权限，仅通过ip地址确定“城市频道”中的城市及相关信息，不会收集精确位置信息。\n3.你可以查看完整版\n如果你同意请点击下面的按钮以接受我们的服务。";

//  List<BottomNavigationBarItem> items = [
//    BottomNavigationBarItem(icon: getIcon(0), title: getTitle(0)),
//    BottomNavigationBarItem(icon: getIcon(1), title: getTitle(1)),
//    BottomNavigationBarItem(icon: getIcon(2), title: getTitle(2)),
//    BottomNavigationBarItem(icon: getIcon(3), title: getTitle(3)),
//  ];

  Widget body = Scaffold();
  BuildContext context;

  @override
  void initState() {
    super.initState();

    WindowUtil.setStatusBar(Colors.white, true);

    Map<String, String> map = Map();
    map["j"] = "1";
    map["a"] = "2";
    map["f"] = "3";
    map["g"] = "4";
    fluwxUtil.wxpay_md5(map);


//    get(Config.baseUrl);
  }



  @override
  Widget build(BuildContext context) {
    this.context = context;
    WindowUtil.window_width = MediaQuery.of(context).size.width;
    WindowUtil.statusbar_height = MediaQuery.of(context).padding.top;
    init(context);
//    return  body;
    return buildBody();
    ;
  }
//  void setJpush(){
//    jpush.setup(appKey: "6be47affa7f4896dfd9aea24" ,channel: 'developer-default',production:false,debug: true);
//    jpush.applyPushAuthority(new NotificationSettingsIOS( sound: true, alert: true, badge: true));
//    jpush.getRegistrationID().then((v){
//      print("flutter 接收到推送: ${v}");
//      controller?.evaluateJavascript('set_jpid("${index}")')?.then((result) {
//        // You can handle JS result here.
//      });
//    });
//    // 监听jpush
//    jpush.addEventHandler(
//      onReceiveNotification: (Map<String, dynamic> message) async {
//        print("flutter 接收到推送: $message");
//        //Fluttertoast.showToast(msg: "$message");
//        Fluttertoast.showToast(msg: "${jpush.getRegistrationID()}");
//      },
//      onOpenNotification: (Map<String, dynamic> message) {
//        // 点击通知栏消息，在此时通常可以做一些页面跳转等
//
//      },
//    );
//  }
  Widget buildBody() {
    print(">>>1");

    return WillPopScope(
        child: Scaffold(
          body: getPage(),
          bottomNavigationBar:
//            bottom3()

          BottomNavigationBar(
              backgroundColor: Colors.white,
              selectedFontSize: 9,
              unselectedFontSize: 9,
              items: [
                BottomNavigationBarItem(
                    icon: getIcon1(0), title: getTitle1(0)),
                BottomNavigationBarItem(
                    icon: getIcon1(1), title: getTitle1(1)),
                BottomNavigationBarItem(
                    icon: getIcon1(2), title: getTitle1(2)),
                BottomNavigationBarItem(
                    icon: getIcon1(3), title: getTitle1(3)),
                BottomNavigationBarItem(
                    icon: getIcon1(4), title: getTitle1(4)),
              ],
              onTap: tap,
              iconSize: 10.0,
              type: BottomNavigationBarType.fixed),
        ),
        onWillPop: () {
          // http://hhnh5.test.freshqiao.com/#/tap/category

          // initialUrl: "http://192.168.10.101:8283/#/",
          //  initialUrl: "http://192.168.10.196:8281/#/tap/home",
          // http://hhnh5.test.freshqiao.com/#/tap/shopping?style=flutter
          // http://hhnh5.test.freshqiao.com/#/tap/my
          controller.currentUrl().then((String v) {
            if (v.startsWith("${Config.baseUrl}#/tap/home")) {
              if (v.startsWith("${Config.baseUrl}#/tap/home?line=api-ds")) {
                if (lastPopTime == null ||
                    DateTime.now().difference(lastPopTime) >
                        Duration(seconds: 2)) {
                  lastPopTime = DateTime.now();
                  Fluttertoast.showToast(msg: "再按一次退出");
                } else {
                  lastPopTime = DateTime.now();
                  // 退出app
                  SystemChannels.platform.invokeMethod('SystemNavigator.pop');
                }
              } else {
                //  Fluttertoast.showToast(msg: "2");
                controller
                    ?.evaluateJavascript('gotoBusinessLine("1")')
                    ?.then((result) {
                  // Fluttertoast.showToast(msg: "1");
                  // You can handle JS result here.
                });
                //controller.evaluateJavascript("gotoBusinessLine");
              }
            } else if (v.startsWith("${Config.baseUrl}#/tap/category") ||
                v == ("${Config.baseUrl}#/tap/shopping?style=flutter") ||
                v == ("${Config.baseUrl}#/tap/my") ||
                v == ("${Config.baseUrl}#/tap/foodrecommend")) {
              controller.loadUrl("${Config.baseUrl}#/tap/home");
              currentTab = 0;
            } else {
              controller.canGoBack().then((v) {
                if (v) {
                  controller.goBack();
                } else {
                  if (lastPopTime == null ||
                      DateTime.now().difference(lastPopTime) >
                          Duration(seconds: 2)) {
                    lastPopTime = DateTime.now();
                    Fluttertoast.showToast(msg: "再按一次退出");
                  } else {
                    lastPopTime = DateTime.now();
                    // 退出app
                    SystemChannels.platform.invokeMethod('SystemNavigator.pop');
                  }
                }
              });
            }
          });

          print("2");
        });
  }

  Future cango() async {
    bool can = await controller.canGoBack();
    return can;
  }

  void tap(int index) {
    //  toast("${index}");

    currentTab = index;
    if (index > 2) {
      //currentTab--;
    }
    setState(() {});

    controller?.evaluateJavascript('flutter("${index}")')?.then((result) {
      // You can handle JS result here.
    });
    print(">>>>${index}");
  }

  Widget getPage() {
    return SafeArea(
        child: Stack(
          children: <Widget>[
            WebView(
              initialUrl: Config.baseUrl,
//          initialUrl: "http://www.baidu.com",

              // http://hhnh5.test.freshqiao.com/#/tap/category

              // initialUrl: "http://192.168.10.101:8283/#/",
              //  initialUrl: "http://192.168.10.196:8281/#/tap/home",
              // http://hhnh5.test.freshqiao.com/#/tap/shopping?style=flutter
              // http://hhnh5.test.freshqiao.com/#/tap/my

              javascriptMode: JavascriptMode.unrestricted,
              onPageFinished: (v) {
//            setJpush();

                controller
                    ?.evaluateJavascript('flutter_lod("${index}")')
                    ?.then((result) {});
                width = 0;
                controller.currentUrl().then((v) {
                  print("currentPage>>>${v}");
                });

                // _initLocation();
                setState(() {});
              },
              onWebViewCreated: (WebViewController web) {
                controller = web;

//            String contentBase64 = base64Encode(
//                const Utf8Encoder().convert(kNavigationExamplePage));
//            controller.loadUrl('data:text/html;base64,$contentBase64');
              },

              javascriptChannels: <JavascriptChannel>[
                _alertJavascriptChannel1(),
                _alertJavascriptChannel2(),
                _alertJavascriptChannel3(),
                _alertJavascriptChannel4(),
                _alertJavascriptChannel5(),
              ].toSet(),
            ),
//        Container(width: windowWidth,height:MediaQuery.of(context).size.height,
//        child: TextField(),
//        ),

            Container(
              width: width,
              child: Center(
                child: new CircularProgressIndicator(
                  //0~1的浮点数，用来表示进度多少;如果 value 为 null 或空，则显示一个动画，否则显示一个定值
                    value: null,

                    //背景颜色
                    backgroundColor: Colors.white,
                    //进度颜色
                    valueColor: new AlwaysStoppedAnimation<Color>(Colors.grey)),
              ),
            )
          ],
        ));
  }

  callback(shopNum) {
    shoppongNum = shopNum;
    setState(() {});
  }

  Widget bage() {
    return Opacity(
      opacity: shoppongNum == 0 ? 0.0 : 1.0,
      child: Badge(
        position: BadgePosition(top: 0, right: 0),
        // padding: EdgeInsets.all(0),
        badgeColor: Colors.red,
        shape: BadgeShape.circle,
//        borderRadius: 10,
        toAnimate: false,
        badgeContent: Text('${shoppongNum}',
            style: TextStyle(color: Colors.white, fontSize: 10)),
      ),
    );
  }

  Widget customBage() {
    return Opacity(
      opacity: shoppongNum == 0 ? 0.0 : 1.0,
      child: Container(
        decoration: BoxDecoration(color: Colors.red, shape: BoxShape.circle),
        padding: EdgeInsets.all(5),
        child: Text('${shoppongNum}',
            style: TextStyle(color: Colors.white, fontSize: 10)),
      ),
    );
  }

//  final _amapLocation = AMapLocation();
//  var _result = '';
//
//  //初始化定位监听
//  void _initLocation() async {
//    _amapLocation.init();
//
//    final options = LocationClientOptions(
//      isOnceLocation: false,
//      locatingWithReGeocode: true,
//    );
//
//    if (await Permissions.requestMapPermission()) {
//      _amapLocation.startLocate(options).listen((_) => setState(() {
//            _result =
//                '坐标：${_.longitude}，${_.latitude} @ ${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}';
//            // print(_.latitude);
//            // Fluttertoast.showToast(msg: "${_.latitude}");
//
//            requestTencent(_.latitude, _.longitude);
//          }));
//    } else {
//      setState(() {
//        _result = "无定位权限";
//      });
//    }
//  }

//  Future initStatus() async {
//    WindowUtil.statusbar_height = await FlutterStatusbar.height;
//  }

  void requestTencent(double lat, double ln) async {
    try {
      // http://hhnrest2yxbk.test.freshqiao.com/Product/1?t=1569395229106&k=4660d11402620c44d2e92e0910808c29&customer_id=2&uuid=b145a130-1d98-d32c-f1c5-bf8624368608&platform=weishop&device=micromessenger&v=2

      //  Map<String ,dynamic> map1 = await  HttpClient.requestHome(Config.baseUrl+"CategoryList",data:map);
      Map<String, dynamic> map = Map();

      Map<String, dynamic> map1 = await HttpClient.requestTencent(
          "https://apis.map.qq.com/ws/coord/v1/translate?locations=${lat},${ln}&type=5&key=I7RBZ-UXB6P-LDJDD-L66QI-RVLNS-5JBUR",
          data: map);
      // Map<String ,dynamic> map1 = await  HttpClient.requestProductDetail('http://hhnrest2yxbk.test.freshqiao.com/Product/1?t=1569395229106&k=4660d11402620c44d2e92e0910808c29&customer_id=2&uuid=b145a130-1d98-d32c-f1c5-bf8624368608&platform=weishop&device=micromessenger&v=2');
      TencentGeoEntity tencentGeoEntity = TencentGeoEntity.fromJson(map1);
      //  t=1568972414822&k=57b4e4cdb289a073a340e9ed7b5044fa&customer_id=2&uuid=816604fa-f57d-b47c-b32b-3fe12f0c4d85&platform=weishop&device=micromessenger&v=2&customer_id=2
      if (tencentGeoEntity == null) {
        print("null");
      } else if (tencentGeoEntity.status == 0) {
        print("not null");
        controller
            ?.evaluateJavascript(
            'flutter_lod("${tencentGeoEntity.locations[0].lat.abs()},${tencentGeoEntity.locations[0].lng.abs()}")')
            ?.then((result) {});
      }
    } catch (e) {}
    print("err  ");
    // HttpUtil.get(baseUrl+"HomePagePreview?t=1568972414822&k=57b4e4cdb289a073a340e9ed7b5044fa&customer_id=2&uuid=816604fa-f57d-b47c-b32b-3fe12f0c4d85&platform=weishop&device=micromessenger&v=2&customer_id=2");
  }

  JavascriptChannel _alertJavascriptChannel(BuildContext context) {
    return JavascriptChannel(
        name: 'setTabBarVisible',
        onMessageReceived: (JavascriptMessage message) {});
  }

  JavascriptChannel _alertJavascriptChannel1() {
    return JavascriptChannel(
        name: 'setShopCartNum',
        onMessageReceived: (JavascriptMessage message) {
          try {
            shoppongNum = int.parse(message.message);
          } catch (e) {
            print(">>>set" + e.toString());
          }

          // Fluttertoast.showToast(msg: "shop");
          setState(() {});
        });
  }

  JavascriptChannel _alertJavascriptChannel2() {
    return JavascriptChannel(
        name: 'setTabSelect',
        onMessageReceived: (JavascriptMessage message) {
          print(">>>message");
          //  print(">>>message${message.message}");
          // Fluttertoast.showToast(msg: "1");
          if (message.message == "1") {
            currentTab = 0;
          }
          if (message.message == "2") {
            currentTab = 1;
          }
          if (message.message == "3") {
            currentTab = 2;
          }
          if (message.message == "4") {
            currentTab = 3;
          }
          if (message.message == "5") {
            currentTab = 4;
          }
          setState(() {});
        });
  }

  JavascriptChannel _alertJavascriptChannel3() {
    return JavascriptChannel(
        name: 'shareLinkToSession',
        onMessageReceived: (JavascriptMessage message) {
          print(">>>message");
          // toast("${message.message}");
          print(message.message);

          // String s ='{"title":"牛掰","desc":"12","link":"http://docker.hhn.weixin.local//#/product_share_order?product_sku_id=394&share_client_id=1&customer_id=5&api=api-ds","imgUrl":"http://aweb.oss-cn-hangzhou.aliyuncs.com/files/20191023144959866.jpg"}";

          try {
            Map<String, dynamic> map =
            JsonUtil.json2map(message.message.toString());

            print(">>>map${map["title"]}");
            LinkEntity linkEntity = LinkEntity.fromJson(map);
            print(">>>>>${linkEntity.imgUrl}");
//            fluwxUtil.shareLinktoSession(linkEntity.link, linkEntity.title,
//                linkEntity.imgUrl, linkEntity.desc);
          } catch (e) {
            print(">>>${e.toString()}");
          }

          setState(() {});
        });
  }

  JavascriptChannel _alertJavascriptChannel4() {
    return JavascriptChannel(
        name: 'sharePosterToSession',
        onMessageReceived: (JavascriptMessage message) {
          print(">>>message");
          // toast("${message.message}");
          print(message.message);
//          FileUtil.saveBase64toGallery(message.message).then((v) {
//            // toast("${v}");
//            fluwxUtil.shareImagetoSession(v, v);
//          });

          setState(() {});
        });
  }

  JavascriptChannel _alertJavascriptChannel5() {
    return JavascriptChannel(
        name: 'wxpay',
        onMessageReceived: (JavascriptMessage message) {
          print(">>>message");
          // toast("${message.message}");
          print(">>>${message.message}");
          try {
            Map<String, dynamic> map =
            JsonUtil.json2map(message.message.toString());

            print(">>>map${map["title"]}");
            WxpayEntity linkEntity = WxpayEntity.fromJson(map);
            fluwx
                .payWithWeChat(
                appId: linkEntity.appid,
                partnerId: linkEntity.partnerid,
                packageValue: linkEntity.package,
                nonceStr: linkEntity.noncestr,
                timeStamp: int.parse(linkEntity.timestamp),
                sign: linkEntity.sign,
                prepayId: linkEntity.prepayid)
                .then((v) {
              controller
                  ?.evaluateJavascript('orderList("1")')
                  ?.then((result) {
                // Fluttertoast.showToast(msg: "1");
                // You can handle JS result here.
              });

//              PayresultEntity linkEntity = PayresultEntity.fromJson(map);
//              if(linkEntity.result){
//
//              }else{
//
//              }
              print(v);
            });
          } catch (e) {
            print(">>>${e.toString()}");
          }
          setState(() {});
        });
  }

  Widget getTitle1(int index) {
    if (index == 0) {
      if (currentTab == index) {
        return Text("首页",
            style: TextStyle(color: Color(0xffff8900), fontSize: 9));
      } else {
        return Text("首页",
            style: TextStyle(color: Color(0xffa3a3a3), fontSize: 9));
      }
    }
    if (index == 1) {
      if (currentTab == index) {
        return Text("分类",
            style: TextStyle(color: Color(0xffff8900), fontSize: 9));
      } else {
        return Text("分类",
            style: TextStyle(color: Color(0xffa3a3a3), fontSize: 9));
      }
    }
    if (index == 2) {
      if (currentTab == index) {
        return Text("发现",
            style: TextStyle(color: Color(0xffff8900), fontSize: 9));
      } else {
        return Text("发现",
            style: TextStyle(color: Color(0xffa3a3a3), fontSize: 9));
      }
    }
    if (index == 3) {
      if (currentTab == index) {
        return Text("购物车",
            style: TextStyle(color: Color(0xffff8900), fontSize: 9));
      } else {
        return Text("购物车",
            style: TextStyle(color: Color(0xffa3a3a3), fontSize: 9));
      }
    }
    if (index == 4) {
      if (currentTab == index) {
        return Text("我的",
            style: TextStyle(color: Color(0xffff8900), fontSize: 9));
      } else {
        return Text("我的",
            style: TextStyle(color: Color(0xffa3a3a3), fontSize: 9));
      }
    }
  }

  Widget getIcon1(int index) {
    if (index == 0) {
      if (currentTab == index) {
        return Container(
          width: 25,
          height: 25,
          alignment: Alignment.bottomCenter,
          child: Image.asset(
            "assets/homeselect.png",
            width: 20.0,
            height: 20,
            fit: BoxFit.fill,
          ),
        );
      } else {
        return Container(
          width: 25,
          height: 25,
          alignment: Alignment.bottomCenter,
          child: Image.asset(
            "assets/home.png",
            width: 20.0,
            height: 20,
            fit: BoxFit.fill,
          ),
        );
      }
    }

    if (index == 1) {
      if (currentTab == index) {
        return Container(
          width: 25,
          height: 25,
          alignment: Alignment.bottomCenter,
          child: Image.asset(
            "assets/chanpinselect.png",
            width: 20.0,
            height: 20,
            fit: BoxFit.fill,
          ),
        );
      } else {
        return Container(
          width: 25,
          height: 25,
          alignment: Alignment.bottomCenter,
          child: Image.asset(
            "assets/chanpin.png",
            width: 20.0,
            height: 20,
            fit: BoxFit.fill,
          ),
        );
      }
    }

    if (index == 2) {
      if (currentTab == index) {
        return Container(
          width: 25,
          height: 25,
          alignment: Alignment.bottomCenter,
          child: Image.asset(
            "assets/Group1.png",
            width: 20.0,
            height: 20,
            fit: BoxFit.fill,
          ),
        );
      } else {
        return Container(
          width: 25,
          height: 25,
          alignment: Alignment.bottomCenter,
          child: Image.asset(
            "assets/Group@3x.png",
            width: 20.0,
            height: 20,
            fit: BoxFit.fill,
          ),
        );
      }
    }

    if (index == 3) {
      if (currentTab == index) {
        return Container(
          width: 25,
          height: 25,
          child: Stack(
            children: <Widget>[
              Container(
                width: 25,
                height: 25,
                alignment: Alignment.bottomCenter,
                child: Image.asset(
                  "assets/gouwucheselect.png",
                  width: 20.0,
                  height: 20.0,
                  fit: BoxFit.fill,
                ),
              ),
              Positioned(
                child: customBage(),
                right: 0,
                top: 0,
              )
            ],
          ),
        );
      } else {
        return Container(
          width: 25,
          height: 25,
          child: Stack(
            children: <Widget>[
              Container(
                width: 25,
                height: 25,
                alignment: Alignment.bottomCenter,
                child: Image.asset(
                  "assets/gouwuche.png",
                  width: 20.0,
                  height: 20.0,
                  fit: BoxFit.fill,
                ),
              ),
              Positioned(
                child: customBage(),
                right: 0,
                top: 0,
              )
            ],
          ),
        );
      }
    }

    if (index == 4) {
      if (currentTab == index) {
        return Container(
          width: 25,
          height: 25,
          alignment: Alignment.bottomCenter,
          child: Image.asset(
            "assets/wode_morenselect.png",
            width: 20.0,
            height: 20,
            fit: BoxFit.fill,
          ),
        );
      } else {
        return Container(
          width: 25,
          height: 25,
          alignment: Alignment.bottomCenter,
          child: Image.asset(
            "assets/wode_moren.png",
            width: 20.0,
            height: 20,
            fit: BoxFit.fill,
          ),
        );
      }
    }
  }

  Widget click() {
    if (currentTab != 2) {
      return Image.asset("assets/Group@3x.png");
    } else {
      return Image.asset("assets/Group1.png");
    }
  }

  Future<Map> get(String url, {data, method}) async {
    data = data ?? {};
    method = 'GET';

    /// restful 请求处理
    /// /gysw/search/hist/:user_id        user_id=27
    /// 最终生成 url 为     /gysw/search/hist/27
//    data.forEach((key, value) {
//      if (url.indexOf(key) != -1) {
//        url = url.replaceAll(':$key', value.toString());
//      }
//    });

    /// 打印请求相关信息：请求地址、请求方式、请求参数
    print('请求地址：【' + method + '  ' + url + '】');
    print('请求参数：' + data.toString());

    Dio dio = createInstance();
    var result;

    try {
      Response response =
      await dio.request(url, options: new Options(method: method));
      // showDialog(context: context,builder: (context){return LoadingDialog(text: "");});
      //  result = response.data;
      body = buildBody();

      /// 打印响应相关信息
      //  print('响应数据：' + response.toString());
    } catch (e) {
      // body = WrongPage(reload);
      /// 打印请求失败相关信息
      print('请求出错：' + e.toString());
      Fluttertoast.showToast(msg: "请求出错");
      dio.reject(e);
      // rethrow;
    } finally {}
    setState(() {});
    return result;
  }

  reload() {
    get(Config.baseUrl);
  }

  Dio createInstance() {
    if (dio == null) {
      /// 全局属性：请求前缀、连接超时时间、响应超时时间
      BaseOptions options = new BaseOptions(
//        baseUrl: API_PREFIX,
        connectTimeout: 1000,
        receiveTimeout: 1000,
      );

      dio = new Dio(options);
    }

    return dio;
  }

  Widget wrongPage() {
    //return conta
  }




}
